﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Skyhook.Logic.VisualControllers;
using Microsoft.Xna.Framework;
using Skyhook.Core;
using Skyhook.Resources;
using Skyhook.Logic;
using Skyhook.AI.Animators;

namespace Skyhook.Logic.Units
{
    class Tank : MovableObject<TankVisualController>
    {
        public int Num = 0;

        LoopInteger TurretAngleController = new LoopInteger(0,32);
        LoopInteger HullAngleController = new LoopInteger(0,32);

        LoopIntegerAnimator TurretAnimator = null;
        LoopIntegerAnimator HullAnimator = null;

        public Tank(string assetname, int startx, int starty, float speed, float rotatespeed)
            : base(assetname, startx, starty, speed, rotatespeed)
        {
        }

        protected override void Initialize()
        {
            base.Initialize();

            Random random = new Random();

            VisualController.SetAngleControllers(HullAngleController, TurretAngleController);

            TurretAngleController.Change(random.Next(32));
            HullAngleController.Change(random.Next(32));

            TurretAnimator = new LoopIntegerAnimator(TurretAngleController);
            TurretAnimator.RotateDelay = 3;
            TurretAnimator.StartAnimation();

            HullAnimator = new LoopIntegerAnimator(HullAngleController);
            HullAnimator.RotateDelay = 6;
            HullAnimator.StartAnimation();

            VisualController.State = TankVisualStates.Normal;
        }

        public override void Update(float elapsedticks)
        {
            base.Update(elapsedticks);

            TurretAnimator.Update(elapsedticks);
            HullAnimator.Update(elapsedticks);
        }
    }
}
